<? session_start();
						
include_once ('core/conn.php');
						
$db = get_conn();
						
check_session();
					
						
$sql = "select i.id_invoice, i.amount, i.due_date, i.exp_date, i.description, l.number, l.id_location
				from `invoices` i , `locations` l where i.istatus='W' and i.id_location = l.id_location order by i.id_invoice";
			
		$result = mysql_query($sql);
		if($result){
			$data ="<table width='80%' align='left' >";
			$cantidad = mysql_num_rows($result) ;
			if($cantidad > 0){
					$data .="<tr>
						<td align='left' >
							&nbsp;
						</td>
						<td align='left' >
							ID
						</td>
						<td align='left' >
							Filial
						</td>							
						<td align='left' >
							Fecha Cobro
						</td>

						
						<td align='left' >
							Monto
						</td>	
						<td align='left' >
							Opciones
						</td>																								
						</tr>";					
				while($row = mysql_fetch_array($result)){
					$controls = "<a onClick='$(this).modal({width:350, height:350}).open(); return false;' href='invoices_edit.php?id=".$row['id_invoice']."'>Editar / Comentarios</a>";	
					$data .="<tr>
						<td><input onclick='enable()' type='checkbox' name='id_invoice[]' value='".$row['id_invoice']."' id='r_".$row['id_invoice']."' ></td>

						<td align='left' >
							".$row['id_invoice']."
						</td>
						<td align='left' >
							".$row['number']." 
						</td>							
						<td align='left' >
							".format_date($row['due_date'])."
						</td>

						<td align='left' >
							".format($row['amount'],2)."
						</td>	
						<td align='left' >
							".$controls."
						</td>																								
						</tr>";
				}//while
			}//if
			else{
				$btn_disabled = true;
				$data .= "<tr><td align='center'>No hay cobros por terminar</td></tr>";			
			}
			$data .="</table>";
		}else{
			error_handling($sql,mysql_error());
		}
?>
<html>
<head>

<link href="tools/modal/base.css" type="text/css" rel="stylesheet" />
<link href="tools/modal/modal-window.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" lang="javascript" src="tools/modal/jquery-1.3.2.min.js"></script>
<script type="text/javascript" lang="javascript" src="tools/modal/modal-window.min.js"></script>
<script>
	function checkdata(obj){
		if(confirm("Esta seguro?")){
			return true;	
		}
		return false;
	}
function refresh_list(){
	url = "ajax_comps/invoices.php"; 
	$("#list_layer").load(url);	
}

function CheckAll(){
	var x = document.getElementById('finish');
	x.disabled = false;

	var x = document.getElementById('delete_selected');
	x.disabled = false;

	
	for(i=0;i<document.getElementsByTagName("input").length;i++){
		if(document.getElementsByTagName("input")[i].type == "checkbox"){
			document.getElementsByTagName("input")[i].checked =true;				
		}
	}
}

function UnCheckAll(chk){
	for(i=0;i<document.getElementsByTagName("input").length;i++){
		if(document.getElementsByTagName("input")[i].type == "checkbox"){
			document.getElementsByTagName("input")[i].checked =false;				
		}
	}
}	

function enable(){
	var x = document.getElementById('finish');
	x.disabled = false;

	var x = document.getElementById('delete_selected');
	x.disabled = false;
}


function do_checker(){

	var text = document.getElementById("xxx").value;
	if(text =='Seleccionar todos'){
		document.getElementById("xxx").value ='Desmarcar todos';
		CheckAll();	
	}else{
		document.getElementById("xxx").value ='Seleccionar todos';
		UnCheckAll();				
	}
}

</script>
</head>

<body>
<form name='invoices' method='post' action='/core/invoices.php' onsubmit='return checkdata(this)'>
  <table width="100%" border="0">
    <tr>
      <td  style="text-align:center">
       <input name='xxx' id='xxx' type='button' value='Seleccionar todos' onClick='do_checker()' <?php if($btn_disabled){echo " disabled ";} ?>>&nbsp;<input disabled type="submit" name="finish" <?php if($btn_disabled){echo " disabled ";} ?> id="finish" value="Terminar y Enviar">
        &nbsp;<input type="submit" name="delete_selected" id="delete_selected" <?php if($btn_disabled){echo " disabled ";} ?> value="Eliminar" disabled>
      </td>
    </tr>
    <tr>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><div id="list_layer"><?php echo $data; ?>
        <input name="cantidad" type="hidden" id="cantidad" value="<?php echo $cantidad?>">
      </div></td>
    </tr>
    <tr>
      <td style="text-align:center">&nbsp;</td>
    </tr>
    <tr>
      <td style="text-align:center">&nbsp;</td>
    </tr>
  </table>
</form>
</body>
</html>
